Skip to main content

Swift - Access Control Visibility Modifiers

In Swift, visibility modifiers (also known as access control levels) determine the accessibility of various parts of your code. Here are the main access levels:

  • Open:
    • The highest level of access. Classes and class members marked as open can be accessed and overridden both within the module they are defined in and in any module that imports that module.
  • Public:
    • Similar to open, but classes and class members marked as public can be accessed but not overridden outside the module.
  • Internal:
    • The default access level. Entities marked as internal can be accessed anywhere within the same module but not outside of it.
  • Fileprivate:
    • Restricts the use of an entity to its own defining source file.
  • Private:
    • The most restrictive access level. Entities marked as private can only be accessed within the enclosing declaration.